package com.beaut.project.control;

import java.util.Map;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import com.beaut.project.service.CoreService;
import com.beaut.project.util.Utility;

/**
 * 负责登录、登出，菜单管理
 * @author 徐凡
 *
 */
@Controller
@RequestMapping("/core")
public class CoreController extends BaseControl{
	@Autowired 
	private CoreService coreService; 
	
    @RequestMapping(value = "/doLogin", method = RequestMethod.POST, produces = "application/json;charset=UTF-8")
    public @ResponseBody String doLogin(HttpServletRequest request) {
    	return coreService.doLogin(this.requestParameterToMap(request),request);
    }
    @RequestMapping(value = "/doLogOut", method = RequestMethod.POST, produces = "application/json;charset=UTF-8")
    public @ResponseBody String doLogOut(HttpServletRequest request) {
    	Map<String,Object> map = getSessionUser(request);
    	if(map != null){
    		com.beaut.project.util.Utility.cache.remove(String.valueOf(map.get("id")));
    	}
    	HttpSession session = request.getSession(false);
	    if (session != null){
	    	session.invalidate();
	    }
	    return Utility.rtJson(Utility.RETURN_OK, null, null);
    }
    
    @RequestMapping(value = "/getShowMenu", method = RequestMethod.POST, produces = "application/json;charset=UTF-8")
    public @ResponseBody String getShowMenu(HttpServletRequest request) {
    	return coreService.getShowMenu(request,getSessionUser(request));
    }
    /**
     * 待处理的工单列表
     * @param request
     * @return
     */
    @RequestMapping(value = "/getShowGd", method = RequestMethod.POST, produces = "application/json;charset=UTF-8")
    public @ResponseBody String getShowGd(HttpServletRequest request) {
    	return coreService.getShowGd(requestParameterToMap(request));
    }
    /**
     * 待处理的项目
     * @param request
     * @return
     */
    @RequestMapping(value = "/getShowXm", method = RequestMethod.POST, produces = "application/json;charset=UTF-8")
    public @ResponseBody String getShowXm(HttpServletRequest request) {
    	return coreService.getShowXm(requestParameterToMap(request));
    }
    
    /**
     * 
     * @param request
     * @return
     */
    @RequestMapping(value = "/getMenu1", method = RequestMethod.POST, produces = "application/json;charset=UTF-8")
    public @ResponseBody String getMenu1(HttpServletRequest request) {
    	return coreService.getMenu1(getSessionUser(request));
    }
    
    /**
     * 
     * 系统管理处 获取所有菜单treegrid
     * @param request
     * @return
     */
    @RequestMapping(value = "/getMenus", method = RequestMethod.POST, produces = "application/json;charset=UTF-8")
    public @ResponseBody String getMenus(HttpServletRequest request) {
    	return coreService.getMenus();
    }
    @RequestMapping(value = "/addMenu", method = RequestMethod.POST, produces = "application/json;charset=UTF-8")
    public @ResponseBody String addMenu(HttpServletRequest request) {
    	return coreService.addMenu(requestParameterToMap(request));
    }
    @RequestMapping(value = "/deleteMenu", method = RequestMethod.POST, produces = "application/json;charset=UTF-8")
    public @ResponseBody String deleteMenu(HttpServletRequest request) {
    	return coreService.deleteMenu(request.getParameter("id"));
    }
    @RequestMapping(value = "/getMenu", method = RequestMethod.GET, produces = "application/json;charset=UTF-8")
    public @ResponseBody String getMenu(HttpServletRequest request) {
    	return coreService.getMenu(request.getParameter("id"));
    }
    @RequestMapping(value = "/updateMenu", method = RequestMethod.POST, produces = "application/json;charset=UTF-8")
    public @ResponseBody String updateMenu(HttpServletRequest request) {
    	return coreService.updateMenu(requestParameterToMap(request));
    }
}
